##!/usr/bin/env python3
import numpy as np
from pandas import DataFrame

"""
函数说明:创建数据
parameter:
    N - 输入的数据个数
return:
    nodeDataFrame - dataFrame化的数据
"""
def createData(N):
    nodeData = np.random.randint(8,size = (N,3))   #产生3列N行范围在（0，6）间的数据
    nodeDataFrame = DataFrame(nodeData,columns = ['X','Y','Z']) #将其dataFrame化
    return nodeDataFrame

"""
函数说明：产生set集合和list集合
parameter:
    nodeDataFrame - 数据集
return:
    nodeDataSet - set集合
    nodeDataList - list集合
"""
def getSetAndList(nodeDataFrame):
    nodeDataSet = []   #创建一个空的list
    nodeDataList = []   #创建一个空的list
    for i in range(len(nodeDataFrame)):
        dataSet = [nodeDataFrame.X[i],nodeDataFrame.Y[i],nodeDataFrame.Z[i]]
        if dataSet in nodeDataSet:
            pass
        else:
            nodeDataSet.append(dataSet)
        nodeDataList.append(dataSet)
    return nodeDataSet,nodeDataList

"""
函数说明:利用set集合来划分不同的节点集合
parameter:
    nodeDataList - list集合
    nodeDataSet - set集合
return:
    classfyNode - 划分好的节点list集合
"""
def classfyNodeData(nodeDataList,nodeDataSet):
    classfyNode = []    #空集合
    for setData in nodeDataSet:
        locationList = []   #存放位置
        for i in range(len(nodeDataList)):
            if setData == nodeDataList[i]:
                locationList.append(i)
        classfyNode.append(locationList)

    return classfyNode

"""
函数说明:打印输出值
parameter:
    nodeDataList - list集合
    classfyNode - 分好类的存放位置的list
return:
    无
"""
def printNodeData(nodeDataList,classfyNode):
    i = 1
    for classfyLocation in classfyNode:
        print("SETS%6dset" % i)
        print(i)
        i += 1
        for location in classfyLocation:
            print("%3d " % location,end = '')
        print('')
        print("")

if __name__ == '__main__':
    N = int(input("请输入想要的数据集中有多少个数据:"))
    nodeDataFrame = createData(N)   #得到3行N列且DataFrame化的数据
    # print(nodeDataFrame)  #如果你想看原始数据集数据的话把这行注释掉
    nodeDataSet,nodeDataList = getSetAndList(nodeDataFrame)
    # print(len(nodeDataList),len(nodeDataSet))
    classfyNode = classfyNodeData(nodeDataList,nodeDataSet)
    # print(len(classfyNode))
    # print(classfyNode)
    printNodeData(nodeDataList,classfyNode)
